package com.julian.warehouse.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.julian.warehouse.R;
import com.julian.warehouse.bean.GoodsBean;
import com.julian.warehouse.bean.RecordsBean;

import java.util.List;

/**
 * Created by Administrator on 2018/8/9.
 */

public class RecordsLvAdapter extends BaseAdapter {
    private Context mContext;
    private List<RecordsBean> dataList;

    public RecordsLvAdapter(Context mContext, List<RecordsBean> dataList){
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_records,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        final RecordsBean recordsBean = dataList.get(position);
        holder.tv_gname.setText(recordsBean.getGname());
        holder.tv_flag.setText(recordsBean.getFlag()==0?"入库":"出库");
        holder.tv_count.setText(recordsBean.getCount()+"");
        holder.tv_result.setText(recordsBean.getResult());
        holder.tv_ctime.setText(recordsBean.getCtime());


        return convertView;
    }


    class ViewHolder{
        private final TextView tv_gname;
        private final TextView tv_count;
        private final TextView tv_flag;
        private final TextView tv_result;
        private final TextView tv_ctime;


        public ViewHolder(View v){


            tv_gname = v.findViewById(R.id.tv_gname);
            tv_count = v.findViewById(R.id.tv_count);
            tv_flag = v.findViewById(R.id.tv_flag);
            tv_result = v.findViewById(R.id.tv_result);
            tv_ctime = v.findViewById(R.id.tv_ctime);
        }


    }
}
